<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>创建限时秒杀</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
        }
    </style>
</head>
<body class="bg-gray-100">
    <div class="mx-auto max-w-[393px] h-[852px] bg-white relative overflow-hidden rounded-[40px] shadow-2xl">
        <!-- Status Bar -->
        <div class="bg-white px-6 pt-3 pb-2">
            <div class="flex justify-between items-center text-xs">
                <span class="font-semibold">9:41</span>
                <div class="flex space-x-1">
                    <i class="fas fa-signal"></i>
                    <i class="fas fa-wifi"></i>
                    <i class="fas fa-battery-full"></i>
                </div>
            </div>
        </div>

        <!-- Header -->
        <div class="bg-gradient-to-r from-orange-500 to-red-500 px-4 py-3">
            <div class="flex items-center justify-between text-white">
                <a href="b2b-marketing.html" class="text-white">
                    <i class="fas fa-arrow-left text-lg"></i>
                </a>
                <h1 class="text-lg font-semibold">创建限时秒杀</h1>
                <button onclick="saveDraft()" class="text-white hover:opacity-80">
                    <i class="fas fa-save text-lg"></i>
                </button>
            </div>
        </div>

        <!-- Content -->
        <div class="h-[calc(852px-160px)] overflow-y-auto pb-4">
            <form id="flashSaleForm">
                <!-- Activity Basic Info -->
                <div class="bg-white border-b border-gray-200">
                    <div class="px-4 py-4">
                        <h3 class="font-medium mb-4 flex items-center">
                            <i class="fas fa-fire text-orange-500 mr-2"></i>
                            活动基本信息
                        </h3>
                        
                        <div class="space-y-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">活动名称</label>
                                <input type="text" id="activityName" placeholder="请输入秒杀活动名称" 
                                       class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-transparent">
                            </div>
                            
                            <div class="grid grid-cols-2 gap-3">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">开始时间</label>
                                    <input type="datetime-local" id="startTime" 
                                           class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-orange-500 focus:border-transparent">
                                </div>
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">结束时间</label>
                                    <input type="datetime-local" id="endTime" 
                                           class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-orange-500 focus:border-transparent">
                                </div>
                            </div>

                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">活动描述</label>
                                <textarea id="description" rows="3" placeholder="请输入活动描述，让买家了解活动亮点"
                                          class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-transparent resize-none"></textarea>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Activity Rules -->
                <div class="bg-white border-b border-gray-200">
                    <div class="px-4 py-4">
                        <h3 class="font-medium mb-4 flex items-center">
                            <i class="fas fa-cog text-blue-500 mr-2"></i>
                            活动规则
                        </h3>
                        
                        <div class="space-y-4">
                            <div class="grid grid-cols-2 gap-3">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">每人限购</label>
                                    <div class="flex items-center">
                                        <input type="number" id="purchaseLimit" min="1" max="999" placeholder="1" 
                                               class="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-transparent">
                                        <span class="ml-2 text-sm text-gray-600">件</span>
                                    </div>
                                </div>
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">最低价格</label>
                                    <div class="flex items-center">
                                        <span class="text-sm text-gray-600 mr-1">¥</span>
                                        <input type="number" id="minPrice" min="0" step="0.01" placeholder="0.01" 
                                               class="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-transparent">
                                    </div>
                                </div>
                            </div>

                            <div>
                                <label class="flex items-center text-sm">
                                    <input type="checkbox" id="memberOnly" class="mr-2 text-orange-500 focus:ring-orange-500">
                                    <span class="text-gray-700">仅限会员参与</span>
                                </label>
                            </div>

                            <div>
                                <label class="flex items-center text-sm">
                                    <input type="checkbox" id="newUserOnly" class="mr-2 text-orange-500 focus:ring-orange-500">
                                    <span class="text-gray-700">仅限新用户参与</span>
                                </label>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Product Selection -->
                <div class="bg-white border-b border-gray-200">
                    <div class="px-4 py-4">
                        <div class="flex items-center justify-between mb-4">
                            <h3 class="font-medium flex items-center">
                                <i class="fas fa-box text-green-500 mr-2"></i>
                                选择商品
                            </h3>
                            <button type="button" onclick="selectProducts()" 
                                    class="bg-orange-100 text-orange-600 text-sm px-3 py-1 rounded-lg hover:bg-orange-200 transition-colors">
                                添加商品
                            </button>
                        </div>
                        
                        <div id="selectedProducts" class="space-y-3">
                            <!-- Selected products will appear here -->
                            <div class="text-center py-8 text-gray-500">
                                <i class="fas fa-box-open text-4xl mb-2"></i>
                                <p>还未选择商品</p>
                                <p class="text-xs">点击"添加商品"选择参与秒杀的商品</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Marketing Settings -->
                <div class="bg-white border-b border-gray-200">
                    <div class="px-4 py-4">
                        <h3 class="font-medium mb-4 flex items-center">
                            <i class="fas fa-bullhorn text-purple-500 mr-2"></i>
                            营销设置
                        </h3>
                        
                        <div class="space-y-4">
                            <div>
                                <label class="flex items-center text-sm">
                                    <input type="checkbox" id="autoPromote" class="mr-2 text-orange-500 focus:ring-orange-500">
                                    <span class="text-gray-700">自动推广到首页</span>
                                </label>
                                <p class="text-xs text-gray-500 mt-1 ml-6">开启后活动将显示在首页推荐位置</p>
                            </div>

                            <div>
                                <label class="flex items-center text-sm">
                                    <input type="checkbox" id="sendNotification" class="mr-2 text-orange-500 focus:ring-orange-500">
                                    <span class="text-gray-700">发送开始提醒</span>
                                </label>
                                <p class="text-xs text-gray-500 mt-1 ml-6">活动开始前15分钟推送通知</p>
                            </div>

                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">分享文案</label>
                                <textarea id="shareText" rows="2" placeholder="精选好物限时秒杀，错过再等一年！"
                                          class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-transparent resize-none text-sm"></textarea>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Preview -->
                <div class="bg-white">
                    <div class="px-4 py-4">
                        <h3 class="font-medium mb-4 flex items-center">
                            <i class="fas fa-eye text-indigo-500 mr-2"></i>
                            活动预览
                        </h3>
                        
                        <div class="bg-gradient-to-r from-orange-50 to-red-50 rounded-lg p-4 border border-orange-200">
                            <div class="flex items-center mb-2">
                                <span class="bg-red-500 text-white text-xs px-2 py-1 rounded-full font-medium">
                                    <i class="fas fa-fire mr-1"></i>限时秒杀
                                </span>
                                <span class="ml-2 text-xs text-gray-600">剩余00:00:00</span>
                            </div>
                            <h4 id="previewName" class="text-sm font-medium mb-2 text-gray-800">活动名称将在这里显示</h4>
                            <p id="previewDesc" class="text-xs text-gray-600">活动描述将在这里显示</p>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <!-- Bottom Actions -->
        <div class="absolute bottom-0 left-0 right-0 bg-white border-t border-gray-200 p-4">
            <div class="flex gap-3">
                <button onclick="saveDraft()" class="flex-1 bg-gray-100 text-gray-700 py-3 rounded-lg font-medium hover:bg-gray-200 transition-colors">
                    保存草稿
                </button>
                <button onclick="submitActivity()" class="flex-1 bg-gradient-to-r from-orange-500 to-red-500 text-white py-3 rounded-lg font-medium hover:opacity-90 transition-opacity shadow-lg">
                    创建活动
                </button>
            </div>
        </div>
    </div>

    <!-- Product Selection Modal -->
    <div id="productModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-t-3xl w-full max-w-[393px] mx-4 max-h-[70vh] overflow-hidden">
            <div class="flex items-center justify-between p-4 border-b border-gray-200">
                <h3 class="text-lg font-semibold">选择商品</h3>
                <button onclick="closeProductModal()" class="text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times text-xl"></i>
                </button>
            </div>
            
            <div class="p-4 overflow-y-auto max-h-[calc(70vh-120px)]">
                <div class="space-y-3" id="productList">
                    <!-- Mock products -->
                    <div class="flex items-center p-3 border border-gray-200 rounded-lg cursor-pointer hover:bg-gray-50" onclick="toggleProduct(this, 'BT001')">
                        <input type="checkbox" class="mr-3">
                        <img src="https://images.unsplash.com/photo-1505740420928-5e560c06d30e?w=60&h=60&fit=crop" class="w-12 h-12 rounded-lg mr-3">
                        <div class="flex-1">
                            <h4 class="text-sm font-medium">无线蓝牙耳机 Pro Max</h4>
                            <div class="flex items-center mt-1">
                                <span class="text-sm text-red-600 font-bold">¥299</span>
                                <span class="text-xs text-gray-500 line-through ml-2">¥399</span>
                                <span class="text-xs text-green-600 ml-2">库存186</span>
                            </div>
                        </div>
                    </div>

                    <div class="flex items-center p-3 border border-gray-200 rounded-lg cursor-pointer hover:bg-gray-50" onclick="toggleProduct(this, 'SW001')">
                        <input type="checkbox" class="mr-3">
                        <img src="https://images.unsplash.com/photo-1523275335684-37898b6baf30?w=60&h=60&fit=crop" class="w-12 h-12 rounded-lg mr-3">
                        <div class="flex-1">
                            <h4 class="text-sm font-medium">智能手表 Series 6</h4>
                            <div class="flex items-center mt-1">
                                <span class="text-sm text-red-600 font-bold">¥1299</span>
                                <span class="text-xs text-gray-500 line-through ml-2">¥1699</span>
                                <span class="text-xs text-orange-600 ml-2">库存3</span>
                            </div>
                        </div>
                    </div>

                    <div class="flex items-center p-3 border border-gray-200 rounded-lg cursor-pointer hover:bg-gray-50" onclick="toggleProduct(this, 'PB001')">
                        <input type="checkbox" class="mr-3">
                        <img src="https://images.unsplash.com/photo-1484704849700-f032a568e944?w=60&h=60&fit=crop" class="w-12 h-12 rounded-lg mr-3">
                        <div class="flex-1">
                            <h4 class="text-sm font-medium">便携充电宝 20000mAh</h4>
                            <div class="flex items-center mt-1">
                                <span class="text-sm text-red-600 font-bold">¥89</span>
                                <span class="text-xs text-gray-500 line-through ml-2">¥129</span>
                                <span class="text-xs text-green-600 ml-2">库存325</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="flex gap-3 p-4 border-t border-gray-200">
                <button onclick="closeProductModal()" class="flex-1 bg-gray-100 text-gray-700 py-2 rounded-lg font-medium">
                    取消
                </button>
                <button onclick="confirmProductSelection()" class="flex-1 bg-orange-500 text-white py-2 rounded-lg font-medium">
                    确认选择
                </button>
            </div>
        </div>
    </div>

    <script>
        let selectedProductsData = [];

        // Form preview updates
        document.getElementById('activityName').addEventListener('input', function() {
            document.getElementById('previewName').textContent = this.value || '活动名称将在这里显示';
        });

        document.getElementById('description').addEventListener('input', function() {
            document.getElementById('previewDesc').textContent = this.value || '活动描述将在这里显示';
        });

        // Product selection functions
        function selectProducts() {
            document.getElementById('productModal').classList.remove('hidden');
        }

        function closeProductModal() {
            document.getElementById('productModal').classList.add('hidden');
        }

        function toggleProduct(element, productId) {
            const checkbox = element.querySelector('input[type="checkbox"]');
            checkbox.checked = !checkbox.checked;
            
            if (checkbox.checked) {
                element.classList.add('border-orange-500', 'bg-orange-50');
            } else {
                element.classList.remove('border-orange-500', 'bg-orange-50');
            }
        }

        function confirmProductSelection() {
            const selectedProducts = document.querySelectorAll('#productList input[type="checkbox"]:checked');
            selectedProductsData = [];
            
            selectedProducts.forEach(checkbox => {
                const productElement = checkbox.closest('.flex');
                const img = productElement.querySelector('img').src;
                const name = productElement.querySelector('h4').textContent;
                const priceText = productElement.querySelector('.text-red-600').textContent;
                
                selectedProductsData.push({
                    id: productElement.onclick.toString().match(/'([^']+)'/)[1],
                    name: name,
                    image: img,
                    price: priceText
                });
            });
            
            updateSelectedProductsDisplay();
            closeProductModal();
        }

        function updateSelectedProductsDisplay() {
            const container = document.getElementById('selectedProducts');
            
            if (selectedProductsData.length === 0) {
                container.innerHTML = `
                    <div class="text-center py-8 text-gray-500">
                        <i class="fas fa-box-open text-4xl mb-2"></i>
                        <p>还未选择商品</p>
                        <p class="text-xs">点击"添加商品"选择参与秒杀的商品</p>
                    </div>
                `;
                return;
            }

            container.innerHTML = selectedProductsData.map(product => `
                <div class="flex items-center justify-between p-3 bg-gray-50 rounded-lg">
                    <div class="flex items-center">
                        <img src="${product.image}" class="w-12 h-12 rounded-lg mr-3">
                        <div>
                            <h4 class="text-sm font-medium">${product.name}</h4>
                            <span class="text-sm text-red-600 font-bold">${product.price}</span>
                        </div>
                    </div>
                    <button onclick="removeProduct('${product.id}')" class="text-red-500 hover:text-red-700">
                        <i class="fas fa-trash text-sm"></i>
                    </button>
                </div>
            `).join('');
        }

        function removeProduct(productId) {
            selectedProductsData = selectedProductsData.filter(p => p.id !== productId);
            updateSelectedProductsDisplay();
        }

        // Form actions
        function saveDraft() {
            const formData = gatherFormData();
            // In a real app, this would save to server
            showToast('草稿已保存');
        }

        function submitActivity() {
            const formData = gatherFormData();
            
            // Basic validation
            if (!formData.activityName) {
                showToast('请输入活动名称');
                return;
            }
            
            if (!formData.startTime || !formData.endTime) {
                showToast('请设置活动时间');
                return;
            }
            
            if (selectedProductsData.length === 0) {
                showToast('请选择参与活动的商品');
                return;
            }

            // Success simulation
            showToast('秒杀活动创建成功！');
            
            setTimeout(() => {
                window.location.href = 'b2b-marketing.html';
            }, 1500);
        }

        function gatherFormData() {
            return {
                activityName: document.getElementById('activityName').value,
                startTime: document.getElementById('startTime').value,
                endTime: document.getElementById('endTime').value,
                description: document.getElementById('description').value,
                purchaseLimit: document.getElementById('purchaseLimit').value,
                minPrice: document.getElementById('minPrice').value,
                memberOnly: document.getElementById('memberOnly').checked,
                newUserOnly: document.getElementById('newUserOnly').checked,
                autoPromote: document.getElementById('autoPromote').checked,
                sendNotification: document.getElementById('sendNotification').checked,
                shareText: document.getElementById('shareText').value,
                products: selectedProductsData
            };
        }

        // Toast notification
        function showToast(message) {
            const toast = document.createElement('div');
            toast.className = 'fixed top-20 left-1/2 transform -translate-x-1/2 bg-gray-800 text-white px-4 py-2 rounded-lg text-sm z-50';
            toast.textContent = message;
            document.body.appendChild(toast);
            
            setTimeout(() => {
                toast.remove();
            }, 2000);
        }

        // Initialize page
        document.addEventListener('DOMContentLoaded', function() {
            // Set default times
            const now = new Date();
            const tomorrow = new Date(now.getTime() + 24 * 60 * 60 * 1000);
            const dayAfterTomorrow = new Date(now.getTime() + 48 * 60 * 60 * 1000);
            
            document.getElementById('startTime').value = tomorrow.toISOString().slice(0, 16);
            document.getElementById('endTime').value = dayAfterTomorrow.toISOString().slice(0, 16);
        });
    </script>
</body>
</html>